/*
 * Copyright (c) 2018.
 * http://www.ulabcare.com
 */

package com.mt.roll.upms.controller;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.params.EnabledParam;
import com.mt.roll.core.params.IdListParam;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.IdListVo;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.upms.params.ServiceParam;
import com.mt.roll.upms.params.ServiceQueryParam;
import com.mt.roll.upms.service.MicroServiceService;
import com.mt.roll.upms.vo.ServiceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 微服务控制器
 *
 * @author jiff
 * @date 2018/11/14
 * @since 1.0
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_UPMS +"microService")
@Slf4j
@Api(value = "微服务管理", tags = "微服务管理接口", hidden = false)
public class MicroServiceController extends BaseController {
    @Autowired
    private MicroServiceService microServiceService;

    @PostMapping(value = "get")
    @ApiOperation(value = "获取微服务")
    private R<ServiceVo> get(@Validated @RequestBody IdParam idParam) {
        return microServiceService.get(idParam);
    }

    @PostMapping(value = "page")
    @ApiOperation(value = "获取分页微服务列表")
    private R<PageVo<ServiceVo>> page(@Validated({PageGroup.class, Default.class}) @RequestBody ServiceQueryParam ServiceQueryParam) {
        return microServiceService.page(ServiceQueryParam);
    }

    @PostMapping(value = "list")
    @ApiOperation(value = "获取微服务列表")
    private R<List<ServiceVo>> list(@Validated({Default.class}) @RequestBody ServiceQueryParam ServiceQueryParam) {
        return microServiceService.list(ServiceQueryParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增微服务")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody ServiceParam ServiceParam) {
        return microServiceService.add(ServiceParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新微服务")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody ServiceParam ServiceParam) {
        return microServiceService.update(ServiceParam);
    }

    @PostMapping(value = "enabled")
    @ApiOperation(value = "启停微服务")
    private R<IdVo> enabled(@Validated @RequestBody EnabledParam enabledParam) {
        return microServiceService.enabled(enabledParam);
    }


    @PostMapping(value = "delete")
    @ApiOperation(value = "删除微服务")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return microServiceService.delete(idParam);
    }

    @PostMapping(value = "batchDelete")
    @ApiOperation(value = "批量删除微服务")
    private R<IdListVo> delete(@Validated @RequestBody IdListParam idListParam) {
        return microServiceService.delete(idListParam);
    }
}
